//
//  HomeHeadCell.m
//  Ranging_dev
//
//  Created by Mr.Dynasty on 2019/4/1.
//  Copyright © 2019 Mr.Dynasty. All rights reserved.
//

#import "HomeHeadCell.h"

@interface HomeHeadCell ()

@property (strong, nonatomic) UILabel *nameLabel;

@end

@implementation HomeHeadCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self makeCell];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)makeCell {
    
    self.backgroundColor = [UIColor clearColor];
    UIView *backView = [[UIView alloc] init];
    [self addSubview:backView];
    CGFloat height = (SCREEN_WIDTH - 20) * 197 / 357.0;
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(self).offset(UIEdgeInsetsMake(10, 10, 10, 10));
        make.height.equalTo(height);
    }];
    backView.backgroundColor = [UIColor clearColor];
    backView.layer.cornerRadius = 5;
    
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.image = [UIImage imageNamed:@"profile_card_background"];
    [backView addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(backView);
    }];
    
    UIImageView *headImageView = [[UIImageView alloc] init];
    headImageView.image = [UIImage imageNamed:@"headplaceholder"];
    [backView addSubview:headImageView];
    [headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(backView.mas_centerX);
        make.width.height.equalTo(45);
        make.top.equalTo(backView).offset(20);
    }];
    
    _nameLabel = [[UILabel alloc] init];
    _nameLabel.font = RegularDefaultFont;
    _nameLabel.textColor = [UIColor whiteColor];
    [backView addSubview:_nameLabel];
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(headImageView.mas_bottom).offset(5);
        make.centerX.equalTo(backView.mas_centerX);
    }];
    
    UIButton *scoreBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [scoreBtn setBackgroundColor:[UIColor clearColor]];
    [scoreBtn setTitle:NSLocalizedString(@"我的积分\n0", nil) forState:UIControlStateNormal];
    scoreBtn.titleLabel.font = RegularDefaultFont;
    scoreBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
    scoreBtn.titleLabel.numberOfLines = 0;
    [backView addSubview:scoreBtn];
    
    UIButton *chargeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [chargeBtn setBackgroundColor:[UIColor clearColor]];
    [chargeBtn setTitle:NSLocalizedString(@"余额\n0", nil) forState:UIControlStateNormal];
    chargeBtn.titleLabel.font = RegularDefaultFont;
    chargeBtn.titleLabel.numberOfLines = 0;
    chargeBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
    [backView addSubview:chargeBtn];
    
    
    [scoreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backView).offset(UIEdgeInsetsMake(0, 20, 20, 0));
        make.top.equalTo(self->_nameLabel.mas_bottom).offset(20);
        make.height.equalTo(50);
    }];
    
    [chargeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(backView).offset(UIEdgeInsetsMake(0, 0, 20, 20));
        make.top.equalTo(self->_nameLabel.mas_bottom).offset(20);
        make.left.equalTo(scoreBtn.mas_right);
        make.height.equalTo(50);
        make.width.equalTo(scoreBtn);
    }];
}

- (void)showCell:(NSString *)name {
    _nameLabel.text = name;
}

@end
